#include <iostream>
#include <vector>
#include <string>

using namespace std;

string licenseKeyFormatting(string s, int k) {
    int i = s.size()-1, t = 0;
    while(i >= 0){
        if(t == k && s[i] != '-'){
            s.insert(s.begin()+i+1, '-');
            t = 0;
        }
        if(s[i] >= 'a' && s[i] <= 'z'){
            s[i] = s[i] - 'a' + 'A';
        }
        if(s[i] == '-'){
            s.erase(i, 1);
            t--;
        }
        t++; i--;
    }
    return s;
}

int main(){
    string s = "--a-a-a-a--"; int k = 2;
    cout << licenseKeyFormatting(s, k) << endl;
    return 0;
}
